#include<bits/stdc++.h>
using namespace std;

int arr[10][10] = {
	{1,2,3,4,5},
	{16,17,18,19,6},
	{15,24,25,20,7},
	{14,23,22,21,6},
	{13,12,11,10,9}
};
bool ifdetect[10][10];


int main() {
	int toward = 0;//0东 1南 2西 3北
	int i = 0, j = 0;
	while (1) {
		if (toward == 0) {
			cout << arr[i][j] << " ";
			ifdetect[i][j] = true;
			if (arr[i][j] == 25) { break; }
			if (arr[i][j + 1] == 0 || ifdetect[i][j + 1]) {
				toward = 1;
				i++;
			}
			else {
				j++;
			}
		}
		else if (toward == 1) {
			cout << arr[i][j] << " ";
			ifdetect[i][j] = true;
			if (arr[i + 1][j] == 0 || ifdetect[i + 1][j]) {
				toward = 2;
				j--;
			}
			else {
				i++;
			}
		}
		else if (toward == 2) {
			cout << arr[i][j] << " ";
			ifdetect[i][j] = true;
			if (arr[i][j-1] == 0 || ifdetect[i][j-1]) {
				toward = 3;
				i--;
			}
			else {
				j--;
			}
		}
		else if (toward == 3) {
			cout << arr[i][j] << " ";
			ifdetect[i][j] = true;
			if (arr[i-1][j] == 0 || ifdetect[i -1][j]) {
				toward = 0;
				j++;
			}
			else {
				i--;
			}
		}
	}
	return 0;
}